﻿<%@ Page Language="C#" MasterPageFile="~/default.Master" AutoEventWireup="true" CodeBehind="UserDetail.aspx.cs"
    Inherits="BookNet.WebForm5" Title="User Detail" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .style3
        {
            width: 100%;
            border: 0;
        }
        .style4
        {
            width: 115px;
            vertical-align: top;
            border: 0;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Content" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:FormView ID="FormView2" runat="server" DataKeyNames="UserID" DataSourceID="SqlDataSource1">
                <ItemTemplate>
                    <br />
                    <br />
                    <h3>
                        <%# Eval("UserName") %>'s Profile</h3>
                    <br />
                    <table align="left" class="style3" width="100%">
                        <tr>
                            <td class="style4">
                                <asp:Image ID="Image1" runat="server" ImageUrl='<%# ChooseImage(Eval("Avatar").ToString()) %>' />
                            </td>
                            <td style="padding-left: 10px; width: 500px;">
                                <table class="table_footer" width="100%" border="0px">
                                    <tr>
                                        <td colspan="2">
                                            <strong><em>
                                                <asp:Label ID="TitleLabel" runat="server" Text='<%# Bind("FullName") %>' Font-Size="Large" /></strong></em>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <hr />
                                            Phone:
                                            <asp:Label ID="ISBNLabel" runat="server" Text='<%# Bind("Phone") %>' />
                                        </td>
                                        <td>
                                            Email: <a href="#">
                                                <asp:Label ID="SellerLabel" runat="server" Text='<%# Bind("Email") %>' /></a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            Faculty:
                                            <asp:Label ID="AuthorLabel" runat="server" Text='<%# Bind("Faculty") %>' />
                                        </td>
                                        <td>
                                            Birthday:<asp:Label ID="DateofBirthLabel" runat="server" Text='<%# Bind("DateofBirth") %>'></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Bind("Bio") %>' />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                &nbsp;
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
            </asp:FormView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:booknetConnectionString1 %>"
                OnSelecting="SqlDataSource1_Selecting" SelectCommand="SELECT app_UserProfile.Avatar, app_UserProfile.Phone, app_UserProfile.Bio, app_UserProfile.Favorites, app_UserProfile.Faculty, app_UserProfile.DateofBirth, app_UserProfile.Books, app_UserProfile.Gender, app_UserProfile.FullName, app_UserProfile.UserID, aspnet_Membership.Email, aspnet_Users.UserName FROM app_UserProfile INNER JOIN aspnet_Membership ON app_UserProfile.UserID = aspnet_Membership.UserId INNER JOIN aspnet_Users ON app_UserProfile.UserID = aspnet_Users.UserId WHERE (app_UserProfile.UserID = @UserID)">
                <SelectParameters>
                    <asp:Parameter Name="UserID" />
                </SelectParameters>
            </asp:SqlDataSource>
            <hr />
            <h5>
                Comments</h5>
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:booknetConnectionString1 %>"
                DeleteCommand="DELETE FROM [app_Comments] WHERE [ID] = @ID" InsertCommand="INSERT INTO [app_Comments] ([ID], [ObjectID], [Rating], [Comment], [TimeAdded]) VALUES (@ID, @ObjectID, @Rating, @Comment, @TimeAdded)"
                SelectCommand="SELECT * FROM [app_Comments] WHERE ([ObjectID] = @ObjectID) ORDER BY [TimeAdded] DESC"
                UpdateCommand="UPDATE [app_Comments] SET [ObjectID] = @ObjectID, [Rating] = @Rating, [Comment] = @Comment, [TimeAdded] = @TimeAdded WHERE [ID] = @ID"
                OnSelecting="SqlDataSource2_Selecting">
                <SelectParameters>
                    <asp:Parameter Name="ObjectID" />
                </SelectParameters>
                <DeleteParameters>
                    <asp:Parameter Name="ID" Type="Object" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="ObjectID" Type="Object" />
                    <asp:Parameter Name="Rating" Type="Int32" />
                    <asp:Parameter Name="Comment" Type="String" />
                    <asp:Parameter Name="TimeAdded" Type="DateTime" />
                    <asp:Parameter Name="ID" Type="Object" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="ID" Type="Object" />
                    <asp:Parameter Name="ObjectID" Type="Object" />
                    <asp:Parameter Name="Rating" Type="Int32" />
                    <asp:Parameter Name="Comment" Type="String" />
                    <asp:Parameter Name="TimeAdded" Type="DateTime" />
                </InsertParameters>
            </asp:SqlDataSource>
            <asp:ListView ID="ListView1" runat="server" DataKeyNames="ID" DataSourceID="SqlDataSource2">
                <ItemTemplate>
                    <table width="700">
                        <tr>
                            <td style="width: 115px; vertical-align: top;">
                                <asp:Image ID="Image1" runat="server" ImageUrl='images/anonymous.gif' Width="100" />
                            </td>
                            <td style="width: 585px; vertical-align: top; padding-top: 10px;">
                                <table width="100%">
                                    <tr>
                                        <td align="left">
                                            Rating:
                                            <cc1:Rating ID="Rating2" runat="server" ReadOnly="true" MaxRating="5" StarCssClass="ratingStar"
                                                WaitingStarCssClass="savedRatingStar" FilledStarCssClass="filledRatingStar" EmptyStarCssClass="emptyRatingStar"
                                                CurrentRating='<%# Eval("Rating") %>'>
                                            </cc1:Rating>
                                        </td>
                                        <td align="right">
                                            <asp:Label ID="Label2" runat="server" Text='<%# Eval("TimeAdded") %>'></asp:Label>
                                        </td>
                                    </tr>
                                </table>
                                <br />
                                Comment:
                                <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Comment") %>'></asp:Label>
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
                <AlternatingItemTemplate>
                    <table width="700" style="background-color: #CCFFCC;">
                        <tr>
                            <td style="width: 115px; vertical-align: top;">
                                <asp:Image ID="Image1" runat="server" ImageUrl='images/anonymous.gif' Width="100" />
                            </td>
                            <td style="width: 585px; vertical-align: top; padding-top: 10px;">
                                <table width="100%">
                                    <tr>
                                        <td>
                                            Rating:
                                            <cc1:Rating ID="Rating2" runat="server" ReadOnly="true" MaxRating="5" StarCssClass="ratingStar"
                                                WaitingStarCssClass="savedRatingStar" FilledStarCssClass="filledRatingStar" EmptyStarCssClass="emptyRatingStar"
                                                CurrentRating='<%# Eval("Rating") %>'>
                                            </cc1:Rating>
                                        </td>
                                        <td align="right">
                                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("TimeAdded") %>'></asp:Label>
                                        </td>
                                    </tr>
                                </table>
                                <br />
                                Comment:
                                <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Comment") %>'></asp:Label>
                            </td>
                        </tr>
                    </table>
                </AlternatingItemTemplate>
                <EmptyDataTemplate>
                    No data was returned.
                </EmptyDataTemplate>
                <LayoutTemplate>
                    <div style="text-align: left; background-color: #FFFFFF; font-family: Verdana, Arial, Helvetica, sans-serif;
                        color: #000000; width: 700px; padding-left: 0px;">
                        <table id="itemPlaceholderContainer" runat="server" style="font-family: Verdana, Arial, Helvetica, sans-serif;
                            list-style-type: none; width: 600px; padding-left: 0px;">
                            <tr style="background-color: #000000; color: #000000; list-style-type: none; padding-left: 0px;">
                                <td id="itemPlaceholder" runat="server">
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div style="text-align: left; background-color: #CCCCCC; font-family: Verdana, Arial, Helvetica, sans-serif;
                        color: #000000; width: 700px;">
                        <asp:DataPager ID="DataPager1" runat="server" PageSize="5">
                            <Fields>
                                <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="True" ShowLastPageButton="True" />
                            </Fields>
                        </asp:DataPager>
                    </div>
                </LayoutTemplate>
                <ItemSeparatorTemplate>
                </ItemSeparatorTemplate>
            </asp:ListView>
            <br />
            <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:booknetConnectionString1 %>"
                DeleteCommand="DELETE FROM [app_Comments] WHERE [ID] = @ID" InsertCommand="INSERT INTO [app_Comments] ([ObjectID], [Rating], [Comment], [TimeAdded]) VALUES (@ObjectID, @Rating, @Comment, @TimeAdded)"
                SelectCommand="SELECT * FROM [app_Comments]" UpdateCommand="UPDATE [app_Comments] SET [ObjectID] = @ObjectID, [Rating] = @Rating, [Comment] = @Comment, [TimeAdded] = @TimeAdded WHERE [ID] = @ID"
                OnInserting="SqlDataSource3_Inserting" 
                oninserted="SqlDataSource3_Inserted">
                <DeleteParameters>
                    <asp:Parameter Name="ID" Type="Object" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="ObjectID" Type="Object" />
                    <asp:Parameter Name="Rating" Type="Int32" />
                    <asp:Parameter Name="Comment" Type="String" />
                    <asp:Parameter Name="TimeAdded" Type="DateTime" />
                    <asp:Parameter Name="ID" Type="Object" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="ObjectID" />
                    <asp:Parameter Name="Rating" Type="Int32" />
                    <asp:Parameter Name="Comment" Type="String" />
                    <asp:Parameter Name="TimeAdded" Type="DateTime" />
                </InsertParameters>
            </asp:SqlDataSource>
            <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="ID"
                DataSourceID="SqlDataSource3" DefaultMode="Insert" Height="50px" Width="125px">
                <Fields>
                    <asp:TemplateField HeaderText="Rating" SortExpression="Rating">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Rating") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <cc1:Rating ID="Rating1" runat="server" CurrentRating="3" MaxRating="5" StarCssClass="ratingStar"
                                WaitingStarCssClass="savedRatingStar" FilledStarCssClass="filledRatingStar" EmptyStarCssClass="emptyRatingStar">
                            </cc1:Rating>
                            <br />
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Rating") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Comment" SortExpression="Comment">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Comment") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Comment") %>' TextMode="MultiLine"
                                Height="100px" Width="615px"></asp:TextBox>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("Comment") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField ShowHeader="False">
                        <InsertItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Insert"
                                Text="Add Comment"></asp:LinkButton>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="New"
                                Text="New"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Fields>
            </asp:DetailsView>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
